//
//  SAHttpApi.m
//  ShopAssistant
//
//  Created by FangGeek on 2017/11/15.
//  Copyright © 2017年 hyxt. All rights reserved.
//

#import "SAHttpApi.h"
#import "SAMKeychain.h"

@implementation SAHttpApi

+ (void)requestGetJsessionidWithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:@"/api/auth/jsessionid" withComeBack:requestSuccess];
}

+ (void)requestLoginWithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:@"/api/auth/jsessionid" withComeBack:requestSuccess];
}

+ (void)requestGetMessageCodeWithPhone:(NSString *)phone WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/auth/verify/%@/%@",[self getDeviceId],phone] withComeBack:requestSuccess];
}


+ (void) requestCheakPhoneWithPhone:(NSString *)phone WithComeBack:(requestSuccess)requestSuccess
{
     [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/auth/mobile/%@",phone] withComeBack:requestSuccess];
}

+ (void) requestBindPhoneWithPhone:(NSString *)phone WithMessageCode:(NSString *)code WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/auth/bind/%@/%@/%@",[self getDeviceId],phone,code] withComeBack:requestSuccess];
}

+ (void) requestListWithPhone:(NSString *)phone WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/shop/list/%@",phone] withComeBack:requestSuccess];
}

+ (void) requestLogOutWithPhone:(NSString *)phone WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/auth/logout/%@/%@",[self getDeviceId],phone] withComeBack:requestSuccess];
}

+ (void) requestGetUserInfoWithPhone:(NSString *)phone WithShopId:(NSString *)shopId WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/auth/emp/%@/%@/%@",shopId,[self getDeviceId],phone] withComeBack:requestSuccess];
}

+ (void)requestGetHTTPURLWithNumber:(NSString *)type WithEmpId:(NSString *)empId WithAppTo:(NSString *)appTo WithComeBack:(requestSuccess)requestSuccess
{
       [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/control/menu/%@/%@/%@",type,empId,appTo] withComeBack:requestSuccess];
}

+ (void)requestGetFanUserInfoWithShopId:(NSString *)shopId WithHyUserId:(NSString *)userId WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypeGet withParaments:nil withCMD:[NSString stringWithFormat:@"/api/auth/fans/%@/%@",shopId,userId] withComeBack:requestSuccess];
}

+ (void)requestSendMessgaeWithParaments:(NSDictionary *)param WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypePostBody withParaments:param withCMD:[NSString stringWithFormat:@"/api/msg/send"] withComeBack:requestSuccess];
}

+ (void)requestPostImageWithParaments:(NSDictionary *)param WithComeBack:(requestSuccess)requestSuccess
{
    [[SAHTTPSessionManager sharedSAHTTPSessionManager] requestWithType:HttpRequestTypePostData withParaments:param withCMD:[NSString stringWithFormat:@"/api/msg/upload"] withComeBack:requestSuccess];
}

+ (NSString *)getDeviceId
{
    NSString * currentDeviceUUIDStr = [SAMKeychain passwordForService:@" "account:@"uuid"];
    if (currentDeviceUUIDStr == nil || [currentDeviceUUIDStr isEqualToString:@""])
    {
        NSUUID * currentDeviceUUID  =[[UIDevice currentDevice] identifierForVendor];
        currentDeviceUUIDStr = [currentDeviceUUID UUIDString];
        currentDeviceUUIDStr = [currentDeviceUUIDStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
        currentDeviceUUIDStr = [currentDeviceUUIDStr lowercaseString];
        [SAMKeychain setPassword: currentDeviceUUIDStr forService:@" "account:@"uuid"];
    }
    return currentDeviceUUIDStr;
}

@end
